<?php
#
# author: Phil Spagnolo
# (c)2008 South Hill Calvary Chapel
#

include_once("./root.inc.php");
include("${root}/mysql/database_info.php");
include("${root}/common.php");
include("${root}/mysql/common.php");

function jwplayer_header($file, $id, $width, $height) {
	printf("<script type='text/javascript' src='./js/JWMediaPlayer5.5/jwplayer.js'></script>\n");
	
	printf("\t<div id='%s'></div>\n", $id);
	
	printf("<script type='text/javascript'>\n");
	printf("jwplayer('%s').setup({\n", $id);
	printf("    'id': 'playerID',\n");
	printf("    'width': '%d',\n", $width);
	printf("    'height': '%d',\n", $height);
	printf("    'controlbar': 'bottom',\n");
	printf("    'file': '%s',\n", $file);
	printf("    'modes': [\n");
	printf("        {type: 'html5'},\n");
	printf("        {type: 'flash', src: './js/JWMediaPlayer5.5/player.swf'},\n");
	printf("        {type: 'download'}\n");
	printf("    ]\n");
	printf("});\n");
	printf("</script>\n");
}

$linkList = array("/current_sermons.php","/sermon.php", "/podcast.php");
$textList = array("Current Sermons", "Archived Sermons", "Podcasts");

$id = $_GET['id'];
$table = $_GET['table'];
if ($id < 1) {
  die ("Error:  іd ($id) is not greater than 0");
} 

connect_select_test($table);

$query="SELECT * FROM $table WHERE id='$id' ORDER BY date DESC";
$result=mysql_query($query) or die (mysql_error());


$date=mysql_result($result,0,"date");
$php_time = strtotime($date);
$xml_date = date("l, F jS, Y", $php_time);

$book=mysql_result($result,0,"book");
$verse=mysql_result($result,0,"verse");
$name=mysql_result($result,0,"name");
$title=mysql_result($result,0,"title");
$title = htmlspecialchars($title, ENT_QUOTES);
$referencedMedia = mysql_result($result,0,"referencedMedia");

$file=mysql_result($result,0,"file");
$file = str_replace("http://www.southhillcalvary.org", "", $file);

$file_video=mysql_result($result,0,"file_video");

$scripture=$book." ".$verse;
$name=add_title($name);

$meta_key=$title.', '.$name.', '.$book.', sermon, teaching, ';
$meta_desc='A sermon by '.$name.' out of the Bible, '.$scripture.', titled: '.$title.'.';
$subtitle = "Sermon:  ".$title;
print_html_head($title ,$meta_key,$meta_desc);

print_java_head(NULL);
begin_body();
page_title($subtitle);

printf("<h4>\n");
printf("\tBy %s\n", $name);
printf("</h4>\n");
printf("<div class='paragraph'>\n");
printf("%s<br/>\n", $xml_date);
printf("%s\n", $scripture);
printf("</div>\n");


printf("<br/>\n");
if (!empty($file)) {
	printf("<h4>Stream or Download the Audio Sermon</h4>\n");
	printf("\t\t<div class='paragraph' >\n");
	if (userIsApple()){
		
		printf("<audio style='width:600px; margin-top:10px;' controls='controls'><source src='%s' type='audio/mpeg' />Your browser does not support the audio element.</audio>", $file);
	}
	else {
		
		$id = 'mediaplayer';
		
		jwplayer_header($file, $id, 600, 24);
	}
	printf("<br><a href='%s'>Download</a>\n", $file);
	printf("</div>\n");
	printf("<br/><br/>\n");
}

if (!empty($file_video)) {
	printf("<h4>Stream the Video Sermon</h4>\n");
	printf("<div>\n");
	printf("\t\t\t%s\n", $file_video); 
	printf("</div>\n");
}

if ($referencedMedia){
	
	printf("<h4>Referenced Media...</h4>\n");
	printf("<div style='width:%s;'>\n", "75%");
	printf("%s", $referencedMedia);
	printf("</div>\n\n");
}

in_page_link(3, false, $linkList, $textList, "");

//Close the database
mysql_close();

end_page_title();
end_body();
?>
